package com.swjd.controller;

import com.swjd.domain.Comment;
import com.swjd.service.ApiCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api")
public class ApiCommentController {
    @Autowired
    private ApiCommentService apiCommentService;


    /*
查询
 */
    @GetMapping("/findById/{id}")
    public Comment findById(@PathVariable("id") Integer id){
        Comment byId = apiCommentService.findById(id);
        return byId;
    }

    /*
    更新
     */
    @GetMapping("/update/{id}/{author}")
    public Integer update(@PathVariable("author") String author ,@PathVariable("id") Integer id){
       Comment comment = apiCommentService.findById(id);
       comment.setAuthor(author);
        Integer i = apiCommentService.update(comment);
        return i;
    }
    /*
    删除
     */
    @GetMapping("/delete/{id}")
    public void delete (@PathVariable("id") Integer id){
        apiCommentService.delete(id);
    }

}
